﻿using System.Linq;
using CID.Domain.Development;
using CID.Tests.Support;
using CID.Web.Controllers;
using NailsFramework.IoC;
using NailsFramework.Persistence;
using NailsFramework.UserInterface.TestingSupport;
using NUnit.Framework;

namespace CID.Web.Tests.Controllers
{
    [TestFixture]
    class ReleaseControllerTests : BaseWebTests
    {
        [Inject]
        public IBag<Release> Releases { private get; set; }

        private Release release;
        private ReleaseStatus originalReleaseStatus;
        private ReleaseController controller;
        
        public override void SetUp()
        {
            base.SetUp();
            controller = TestControllers.Get<ReleaseController>();
            release = Releases.First();
            originalReleaseStatus = release.Status;
        }

        public override void TearDown()
        {
            release.SetProperty(x => x.Status, originalReleaseStatus); 
            base.TearDown();
        }

        [Test]
        public void TestSetActive_ShouldSucceed()
        {
            release.SetProperty(x => x.Status, ReleaseStatus.Planned); 

            controller.SetActive(release.Id);

            Assert.AreEqual(ReleaseStatus.Active, release.Status);
        }

        [Test]
        public void TestSetObsolete_ShouldSucceed()
        {
            release.SetProperty(x => x.Status, ReleaseStatus.Planned);

            controller.SetObsolete(release.Id);

            Assert.AreEqual(ReleaseStatus.Obsolete, release.Status);
        }

        [Test]
        public void TestSetReleased_ShouldSucceed()
        {
            release.SetProperty(x => x.Status, ReleaseStatus.Active);

            controller.SetReleased(release.Id);

            Assert.AreEqual(ReleaseStatus.Released, release.Status);
        }
    }
}
